package com.neusoft.his.sys.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.ibatis.javassist.LoaderClassPath;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

/**
 * 执行逆向工程之前，必须配置YML信息
 * @author admin
 *
 */
public class MyGenerator {
	private static final String URL = "jdbc:mysql://localhost:3306/orcl?serverTimezone=UTC";
	private static final String USERNAME = "root";
	private static final String PASSWORD = "root";
//	SpringApplication 所在类的包名
	private static final String PACKAGE_NAME = "com.neusoft.his.sys";
	private static final String AUTHOR_NAME = "段静迪";
//	 
	private static final String OUTDIR_JAVA = "D:\\admin\\Home\\yd12\\hiss\\hiss\\src\\main\\java";
	private static final String OUTDIR_XML = "D:\\admin\\Home\\yd12\\hiss\\hiss\\src\\main\\resources\\mappers";

	public static void main(String[] args) {
		FastAutoGenerator.create(URL, USERNAME, PASSWORD)
	    .globalConfig(builder -> {
	        builder.author(AUTHOR_NAME) // 设置作者
	               .fileOverride() // 覆盖已生成文件
	               .outputDir(OUTDIR_JAVA) // 指定输出目录
	               .disableOpenDir();    // 禁止打开输出目录	
	    })
	    .packageConfig(builder -> {
	        builder.parent(PACKAGE_NAME) // 设置包名
	            .entity("entity")         //设置实体类包名
	            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, OUTDIR_XML)); // 设置mapperXml生成路径
	    })
	    .strategyConfig(builder -> {
	    	List<String> lss = new ArrayList<>();
//	    	动态调整
	    	lss.add("emp");
	    	lss.add("dept");
	        builder.addInclude(lss) // 设置需要生成的表名
	               .controllerBuilder()   //这里写controllerBuilder，表示将开始controller配置
	               .enableRestStyle();
	    })
	    .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
	    .execute();
	}

}
